<?php
namespace app\index\controller;
use app\index\model\User;
use think\Request;
use think\Db;
use think\helper\Hash;
use think\migration\db\Column;
class Index
{
    private function getdata($data)
    {
        $data = openssl_decrypt($data, config('api.method'), config('api.key'));
        $data = json_decode($data, true);
        return $data;
    }
    public function index()
    {
        return view('Index/index');
    }

    public function info()
    {
        return view("Index/info");
    }

    //接值
    public function add(Request $request)
    {
//        $name="18810980417";
//        $password="123456";
        $name = Request::instance()->param('name');
        $password = Request::instance()->param('password');
         print_r($password);
//        添加数据入库操作
        $data = ['username' => $name, 'password' =>Hash::make($password)];
        $userId =Db::name('user')->insertGetId($data);
        if($userId){
            echo $userId;
        }else{
            echo "no";
        }

//        $list = Db::table('user')->select();//查询所有用户数据
//        $list = Db::table('user')->where('username', $name)->find();//根据用户名查询用户数据
//        if(!Hash::check($password,$list['password'])){
//            echo json_encode(['state'=>'202','msg'=>"登录失败"]);
//        } else {
//            echo json_encode(['state'=>'200','msg'=>"登录成功",'list'=>$list]);
//        }
    }

    //修改编辑
    public function edits(){
        $name = Request::instance()->param('name');
        $id = Request::instance()->param('id');
        $user = new User();

        $result=Db::table('user')->where('id', $id)->update(['username' => $name]);
        if($result !== false) {
            echo 'success';
        }else{
            echo 'false';
        }

    }


}
